class FuelTax < ActiveRecord::Base
  def self.refresh(fromto,tax)
    begin
      tofrom = fromto[3,3]+fromto[0,3]
      fuelTaxs = FuelTax.find(:all,:conditions=>["fromto=? or fromto=?",fromto,tofrom])
      if fuelTaxs && fuelTaxs.length>0
        for f in fuelTaxs
          f.tax = tax.to_i
          f.save
        end
      else
        fuelTax = FuelTax.new
        fuelTax.fromto = fromto
        fuelTax.tax = tax.to_i
        fuelTax.save
        
        fuelTax = FuelTax.new
        fuelTax.fromto = tofrom
        fuelTax.tax = tax.to_i
        fuelTax.save
      end
    rescue Exception => e
      logger.error("FuelTax refresh e="+e.message)
    end
  end
end
